package net.cyndeline.components.agent

import net.cyndeline.entitySystem.Component
import net.cyndeline.GUI.PlayerEngineContainer
import com.escalatesoft.subcut.inject.BindingModule
import com.escalatesoft.subcut.inject.Injectable
import net.cyndeline.GUI.input.PlayerEntityContainer

/**
 * Whatever entity owns this component will be the target of
 * every player input.
 * 
 * When moving this component from one entity to another, 
 * make sure that the player container variable is updates with the 
 * new entity, otherwise the old one will keep receiving the input.
 */
trait PlayerInputComponent extends Component {
  def player: PlayerEngineContainer
  def player_=(newPlayer: PlayerEngineContainer)
}

class PlayerInput(implicit val bindingModule: BindingModule) extends PlayerInputComponent with Injectable {
  private var playerContainer = inject[PlayerEngineContainer]
  
  override def player = playerContainer
  
  override def player_=(newPlayer: PlayerEngineContainer) {
    playerContainer = newPlayer
  }
  
  override def copy = {
    val inputCopy = new PlayerInput()
    inputCopy.player = playerContainer.copy
    inputCopy
  }
}

